vim.g.mapleader = " "

local keymap = vim.keymap

-- ---------- 插入模式 ---------- ---
keymap.set("i", "jk", "<ESC>")

-- ---------- 视觉模式 ---------- ---
-- 单行或多行移动
keymap.set("v", "J", ":m '>+1<CR>gv=gv")
keymap.set("v", "K", ":m '<-2<CR>gv=gv")


keymap.set("n", "J", "5j")
keymap.set("n", "K", "5k")

keymap.set("n", "S", ":w<cr>")
keymap.set("n", "Q", ":q<cr>")



-- ---------- 正常模式 ---------- ---
-- 窗口
keymap.set("n", "<leader>sv", "<C-w>v") -- 水平新增窗口 
keymap.set("n", "<leader>sh", "<C-w>s") -- 垂直新增窗口

-- 取消高亮
keymap.set("n", "<leader>nh", ":nohl<CR>")

-- 切换buffer
keymap.set("n", "<C-L>", "<c-w><c-l>")
keymap.set("n", "<C-H>", "<c-w><c-h>")
keymap.set("n", "<leader>l", ":bnext<CR>")
keymap.set("n", "<leader>h", ":bprevious<CR>")

-- ---------- 插件 ---------- ---
-- nvim-tree
keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>")
keymap.set("n", "<leader>w", ":w<cr>")

local snip_status_ok, luasnip = pcall(require, "luasnip")
if not snip_status_ok then
  return
end

keymap.set({"i"}, "<C-L>", function() luasnip.expand() end, {silent = true})
keymap.set({"i", "s"}, "<C-J>", function() luasnip.jump( 1) end, {silent = true})
keymap.set({"i", "s"}, "<C-K>", function() luasnip.jump(-1) end, {silent = true})

keymap.set({"i", "s"}, "<C-E>", function()
	if luasnip.choice_active() then
		luasnip.change_choice(1)
	end
end, {silent = true})
